<?php
/***************************************************************************
 *   copyright				: (C) 2008, 2009 WeBid
 *   site					: http://www.webidsupport.com/
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version. Although none of the code may be
 *   sold. If you have been sold this script, get a refund.
 ***************************************************************************/

// Connect to sql server & inizialize configuration variables
include 'includes/common.inc.php';

// If user is not logged in redirect to login page
if (!$user->is_logged_in())
{
	header('location: user_login.php');
	exit;
}


// Send buyer's request to the administrator
if (isset($_POST['requesttoadmin']))
{
	$emailer = new email_class();
	$emailer->assign_vars(array(
			'NAME' => $user->user_data['name'],
			'NICK' => $user->user_data['nick'],
			'EMAIL' => $user->user_data['email'],
			'ID' => $user->user_data['id']
			));
	$emailer->email_sender($system->SETTINGS['adminmail'], 'buyer_request.inc.php', $MSG['820']);
	$_SESSION['TMP_MSG'] = $MSG['25_0142'];
}

$cptab = (isset($_GET['cptab'])) ? $_GET['cptab'] : '';

switch ($cptab)
{
	default:
	case 'summary':
		$_SESSION['cptab'] = 'summary';
		break;
	case 'account':
		$_SESSION['cptab'] = 'account';
		break;
	case 'selling':
		$_SESSION['cptab'] = 'selling';
		break;
	case 'buying':
		$_SESSION['cptab'] = 'buying';
		break;
	case 'avatarupload':
		$_SESSION['cptab'] = 'avatarupload';
		break;
}

switch ($_SESSION['cptab'])
{
	default:
	case 'summary':
		$reminders = get_reminders($user->user_data['id']);
		$template->assign_vars(array(
				'NEWMESSAGES'  => ($reminders[0] > 0) ? '<tr><td>' . $MSG['508'] . '</td><td>' . $reminders[0] . $MSG['77_0033'] . '</td><td><a href="' . $system->SETTINGS['siteurl'] . 'mail.php">' . $MSG['5295'] . '</a></td></tr>' : '',
				'FBTOLEAVE'    => ($reminders[1] > 0) ? '<tr><td>' . $MSG['072'] . '</td><td>' . $reminders[1] . $MSG['77_0034'] . '</td><td><a href="' . $system->SETTINGS['siteurl'] . 'buysellnofeedback.php">' . $MSG['5295'] . '</a></td></tr>' : '',
				'TO_PAY'       => ($reminders[2] > 0) ? '<tr><td>' . $MSG['792'] . '</td><td>' . $reminders[2] . $MSG['77_0035'] . '</td><td><a href="' . $system->SETTINGS['siteurl'] . 'outstanding.php">' . $MSG['5295'] . '</a></td></tr>' : '',
				'BENDING_SOON' => ($reminders[3] > 0) ? '<tr><td>' . $MSG['793'] . '</td><td>' . $reminders[3] . $MSG['77_0035'] . '</td><td><a href="' . $system->SETTINGS['siteurl'] . 'yourbids.php">' . $MSG['5295'] . '</a></td></tr>' : '',
				'BOUTBID'      => ($reminders[4] > 0) ? '<tr><td>' . $MSG['794'] . '</td><td>' . $reminders[4] . $MSG['77_0035'] . '</td><td><a href="' . $system->SETTINGS['siteurl'] . 'yourbids.php">' . $MSG['5295'] . '</a></td></tr>' : '',
				'NO_REMINDERS' => (($reminders[0] + $reminders[1] + $reminders[2] + $reminders[3] + $reminders[4]) == 0) ? '<tr><td>' . $MSG['510'] . '</td></tr>' : '',
				));
		break;
	case 'account':
		$reminders = get_reminders($user->user_data['id']);
		$template->assign_vars(array(
				'NEWMESSAGES' => ($reminders[0] > 0) ? '( ' . $MSG['77_0036'] . $reminders[0] . $MSG['77_0033'] . ' )' : '',
				'FBTOLEAVE'   => ($reminders[1] > 0) ? '( ' . $MSG['77_0036'] . $reminders[1] . $MSG['77_0033'] . ' )' : ''
				));
		break;
	case 'selling':
		break;
	case 'buying':
		break;
	case 'avatarupload':
		break;
}

$template->assign_vars(array(
		'B_CANSELL' => ($user->can_sell),

		'TMPMSG' => (isset($_SESSION['TMP_MSG'])) ? $_SESSION['TMP_MSG'] : '',
		'THISPAGE' => $_SESSION['cptab']
		));

$AVATAR_UPL_ERR = '';
if (!empty($_SESSION['AVATAR_UPL_ERR'])) {
	$AVATAR_UPL_ERR = $_SESSION['AVATAR_UPL_ERR'];
	$_SESSION['AVATAR_UPL_ERR'] = '';
}		
		
$template->assign_vars(array(
		'AVATAR' => $user->user_data['avatar'],
		'AVATAR_UPL_ERR' => $AVATAR_UPL_ERR
		));
		
include 'header.php';
include 'includes/user_cp.php';
$template->set_filenames(array(
		'body' => 'user_menu.tpl'
		));
$template->display('body');
include 'footer.php';
unset($_SESSION['TMP_MSG']);
?>
